set more off

*** read data ***

use "reassessments", clear
merge m:m swis_code year using "switchers"
drop _m
merge m:m swis_code year using "salesweb"
keep if _m == 3
drop _m

*** recode for interpretation ***

gen elected = 1-D
replace rar = rar*100

*** do the plots ***


gen B = .
gen SE = .


xtile qprice = lprice, nq(5)
tabulate qprice, gen(qprice_)
forvalues i = 1(1)5 {
	gen qprice_`i'Xelected = qprice_`i'*elected
}
#delimit;
xi: areg rar 
	elected
	qprice_2 qprice_3 qprice_4 qprice_5
	qprice_2Xelected qprice_3Xelected qprice_4Xelected qprice_5Xelected
	i.year, a(swis_code) cl(swis_code)
	;
#delimit cr


mat V = e(V)

replace B = _b[elected] if qprice == 1
replace SE = _se[elected] if qprice == 1
forvalues i = 2(1)5 {
	replace B = _b[elected] + _b[qprice_`i'Xelected] if qprice == `i'
	replace SE = sqrt(V[1,1] + V[`i'+4,`i'+4] + 2*V[`i'+4,1]) if qprice == `i'
}


collapse B SE lprice, by(qprice)
gen UB = B + 1.96*SE
gen LB = B - 1.96*SE

#delimit;

gr tw 
	(sc B qprice, col(black) msize(vlarge))
	(rcap UB LB qprice, col(black))
	(lfit B qprice, col(black) lpat(dash))
	,
		yline(0)
		legend(off)
		plotregion(style(none))
		ytitle("Effect of elected assessor")
		xtitle("Home value (quintile)")	
		ylab(, angle(horiz))
		;

#delimit cr

gr export "figure A4.eps", replace
